package com.dxy.md.user.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxy.md.user.entity.User;
import com.dxy.md.user.mapper.UserMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{

    @Override
    public void saveUser(User user) {
        baseMapper.insert(user);
    }

    @Override
    @DS("slave")
    public User findById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    @Transactional
    @DS("slave")
    public void testTransaction() {
        User user = new User().setName("xxx");
        baseMapper.insert(user);
        throw new RuntimeException("测试事务报错");
    }

    @Override
    public void deleteUser(Long id) {
        baseMapper.deleteUser(id);
    }
}
